home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / drgnsmth.cpt / Dragonsmith 1.1 / Template files / DMenusTmpl.c next >
Encoding:
C/C++ Source or Header  |  1992-10-12  |  5.3 KB  |  155 lines

  1. /*
  2.     DMenusTmpl.c
  3.     
  4.     Template for a simple Dragon sub-species with an added menu
  5.     
  6.     Please note that a dragon based on DMenusTmpl.c and MenusTmpl.╣.rsrc will use a preferences file even though,
  7.         technically, it doesn't need one (since the user won't have any way of changing any preferences).  I did it this
  8.         way for safety's sake, given the possibility that one might later add preferences to a dragon based on it.  To
  9.         prevent it from using a preferences file, put a null string in the 'STR ' 128 resource in MenusTmpl.╣.rsrc
  10.     
  11.     To base a simple dragon (let's call it "Fafnir") on the code in this file ╤
  12.     
  13.     1.    Make a copy of this file and rename it "DFafnir.c"
  14.     2.    Make a copy of the file "Template.╣" and name it "Fafnir.╣"
  15.     3.    Add DFafnir.c to the Fafnir.╣ project
  16.     4.    Change your project "creator" value to your dragon's signature
  17.     5.    Make a copy of the file "MenusTmpl.╣.rsrc" and name it "Fafnir.╣.rsrc"
  18.     6.    Change all instances in this file of the string "MenusTmpl" to "Fafnir"
  19.     7.    Move Fafnir.╣.rsrc up so it's in the same folder as Fafnir.╣
  20.     8.    Make the following changes in Fafnir.╣.rsrc ╤
  21.         ª Use ResEdit 2.1's 'BNDL' editor to change your dragon's signature and add an 'FREF' resource for each document
  22.             type the user can drag-and-drop on your dragon ('****' is all files, 'fold' is folders, and 'disk' is volumes)
  23.         ª Use ResEdit's icon family editor to change your dragon's icon ╤ a boring icon is provided for you to fiddle with
  24.         ª Change the values in 'DrPr' 128 (resolveAliases, dirDepthLimit, etc.), if you wish ╤ do NOT delete this resource
  25.         ª Edit the 'TEXT'/'styl' 128 resources ╤ they provide the Finder's help text for your dragon's icon (or remove these
  26.             two resources, as well as 'hfdr' ╨5696, if you'd rather not have this feature)
  27.         ª Change the value in 'MoMa' 128 if your dragon needs to call MoreMasters when it starts up
  28.         ª Edit the two 'vers' resources
  29.         ª Change the string in 'STR ' 128 to the name of your dragon's preferences file
  30.     9.    Rewrite the method DFafnir::ProcessFile (or ProcessDirectory, or both) so your dragon actually does something
  31.     10.    Add other code as necessary
  32.  
  33.     Created    01 Oct 1992    Framework with Options menu
  34.     Modified    
  35.     
  36. */
  37.                                     
  38. #include    "Dragon.h"
  39.  
  40. enum {
  41.     mOptions = mEdit + 1
  42. };
  43.  
  44. enum {
  45.     // Put your Options menu item constants here
  46.     iNothingAtAll = 1
  47. };
  48.  
  49. class DMenusTmpl: public Dragon {
  50.     
  51.     protected:
  52.         MenuHandle        optionsMenu;            // Delete this instance variable if your dragon doesn't add any menus
  53.  
  54.     public:
  55.                         DMenusTmpl (void);
  56.         virtual void        ProcessFile (void);
  57.         virtual void        ProcessDirectory (void);
  58.     
  59.     protected:
  60.         virtual void        SetUpMenus (void);
  61.         virtual void        DoMenu (long menuItemCode);
  62.         virtual void        DoOptionsMenu (short itemNum);
  63.         virtual void        AdjustMenusBusy (void);
  64.         virtual void        AdjustMenusIdle (void);
  65. };
  66.  
  67. Dragon *CreateGDragon (void)
  68. {
  69.     // This is a function, not a method.  It's declared in Dragon.h and is NOT defined in Dragon.c
  70.     
  71.     return (Dragon *) new DMenusTmpl;
  72. }
  73.  
  74. DMenusTmpl::DMenusTmpl (void)
  75. {
  76.     // You should initialize any added instance variables here ╤ this method will be called whenever an object of
  77.     //    this class is created, immediately after Dragon::Dragon
  78.     
  79.     optionsMenu = NULL;
  80.     autoQuit = FALSE;        // This will be overridden by whatever value for autoQuit is specified in the 'DrPr' 128 resource in
  81.                         //    your project resource file ╤ so just removing this line won't necessarily be enough to make
  82.                         //    it auto-quit.  The file "MenusTmpl.╣.rsrc" has a 'DrPr' 128 that sets autoQuit = FALSE
  83. }
  84.  
  85. void DMenusTmpl::ProcessFile (void)
  86. {
  87.     // This is the heart of your dragon.  You can open the file, change its file attributes, or whatever ╔
  88.     // Simple changes can be simplified by using the macros defined in Dragon.h (curDocIsFile, curFileType, etc.)
  89.     
  90.     // Note that this method will not be called if you open a preferences file created by this dragon ╤ that's
  91.     //    all taken care of for you by Dragon (see ProcessOwnedFile)
  92. }
  93.  
  94. void DMenusTmpl::ProcessDirectory (void)
  95. {
  96.     // Use this method to process folders and disks instead of just ignoring them or looking inside them for files
  97.     // If you don't use this method, you can just delete it (and its declaration above) ╤ I put it here merely for convenience
  98. }
  99.  
  100. void DMenusTmpl::SetUpMenus (void)
  101. {
  102.     // Delete this method if your dragon doesn't add any menus
  103.     
  104.     inherited::SetUpMenus ();            // Add the Apple, File, and Edit menus
  105.  
  106.     optionsMenu = GetMenu (mOptions);
  107.     InsertMenu (optionsMenu, 0);
  108.     
  109.     DrawMenuBar ();
  110. }
  111.  
  112. void DMenusTmpl::DoMenu (long menuItemCode)
  113. {
  114.     // Delete this method if your dragon doesn't add any menus
  115.     
  116.     short    menuID, itemNum;
  117.  
  118.     menuID = menuItemCode >> 16;
  119.     itemNum = menuItemCode & 0xFFFF;
  120.  
  121.     if (menuID == mOptions)
  122.         DoOptionsMenu (itemNum);
  123.     else
  124.         inherited::DoMenu (menuItemCode);
  125. }
  126.  
  127. void DMenusTmpl::DoOptionsMenu (short itemNum)
  128. {
  129.     // Delete this method if your dragon doesn't add any menus
  130.     
  131.     switch (itemNum) {
  132.         // Put your case statements here╔
  133.         default:
  134.             break;
  135.     }
  136. }
  137.  
  138. void DMenusTmpl::AdjustMenusBusy (void)
  139. {
  140.     // Delete this method if your dragon doesn't add any menus
  141.     
  142.     inherited::AdjustMenusBusy ();
  143.     DisableItem (optionsMenu, 0);    // Disable the entire Options menu
  144. }
  145.  
  146. void DMenusTmpl::AdjustMenusIdle (void)
  147. {
  148.     // Delete this method if your dragon doesn't add any menus
  149.     
  150.     inherited::AdjustMenusIdle ();
  151.     EnableItem (optionsMenu, 0);        // Enable what we disabled in AdjustMenusBusy ╤ this will NOT enable items that
  152.                                 //    were disabled to begin with
  153. }
  154.  
  155.